package org.jeecg.modules.online.cgform.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtil;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.JeecgDataAutorUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysPermissionDataRuleModel;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.auth.service.IOnlAuthDataService;
import org.jeecg.modules.online.auth.service.IOnlAuthPageService;
import org.jeecg.modules.online.cgform.components.LinkDown;
import org.jeecg.modules.online.cgform.constant.ExtendJsonKey;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;
import org.jeecg.modules.online.cgform.entity.OnlCgformHead;
import org.jeecg.modules.online.cgform.mapper.OnlCgformFieldMapper;
import org.jeecg.modules.online.cgform.mapper.OnlCgformHeadMapper;
import org.jeecg.modules.online.cgform.mapper.OnlineMapper;
import org.jeecg.modules.online.cgform.model.SqlOrder;
import org.jeecg.modules.online.cgform.model.TreeModel;
import org.jeecg.modules.online.cgform.service.IOnlCgformFieldService;
import org.jeecg.modules.online.cgform.util.CgformUtil;
import org.jeecg.modules.online.config.model.OnlineFieldConfig;
import org.jeecg.modules.online.config.util.ConditionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @Description: Online表单开发
 * @Author: jeecg-boot
 * @Date: 2019-03-12
 * @Version: V1.0
 */
@Service("onlCgformFieldServiceImpl")
@Slf4j
public class OnlCgformFieldServiceImpl extends ServiceImpl<OnlCgformFieldMapper, OnlCgformField> implements IOnlCgformFieldService {

	@Autowired
	private OnlCgformFieldMapper onlCgformFieldMapper;

	@Autowired
	private OnlCgformHeadMapper cgformHeadMapper;

	@Autowired
	private IOnlAuthDataService onlAuthDataService;

	@Autowired
	private IOnlAuthPageService onlAuthPageService;

	@Autowired
	private ISysBaseAPI sysBaseAPI;

	@Autowired
	private OnlineMapper onlineMapper;
	
	/**树形列表根节点父级ID为0*/
	private static final String TREE_ROOT_PID = "0";
	
	@Override
	public Map<String, Object> queryAutolistPage(OnlCgformHead head, Map<String,Object> params, List<String> needList) {

		String tbname = head.getTableName();
		String headId = head.getId();
		Map<String, Object> result = new HashMap<>();

		//1.查询字段集合
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, headId);
		query.orderByAsc(OnlCgformField::getOrderNum);
		List<OnlCgformField> allFieldList = this.list(query);

		//2.获取显示列
		List<OnlCgformField> fieldList = this.queryAvailableFields(headId, tbname, true, allFieldList, needList);

		//2.获取查询sql
		StringBuffer sb = new StringBuffer();
		//基础SQL
		CgformUtil.getAutoListBaseSql(tbname, fieldList, sb);
		//查询条件（数据权限）
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200723 for：online权限改造
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<SysPermissionDataRuleModel> authList = onlAuthDataService.queryUserOnlineAuthData(userId, headId);
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200820 for：online权限改造 遗漏 用户信息临时存储
		if(authList!=null && authList.size()>0){
			JeecgDataAutorUtils.installUserInfo(sysBaseAPI.getCacheUser(sysUser.getUsername()));
		}

		// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
        // sql处理- 获取查询条件
        ConditionHandler handler = new ConditionHandler("t.");
        handler.setNeedList(needList);
        handler.setSubTableStr(head.getSubTableStr());
        List<OnlineFieldConfig> fieldConfigs = CgformUtil.getOnlineFieldList(allFieldList);
        String condition = handler.getConditionSql(fieldConfigs, params, authList);
        Map<String,Object> sqlParam = handler.getSqlParams();
		if(condition.trim().length()>0){
			sb.append(" t ").append(CgformUtil.SQL_WHERE).append(condition);
		}
		// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus

		// 拼接排序
		String orderBySql = getOrderBySql(allFieldList, params);
		sb.append(orderBySql);

		//3.分页查询
		Integer pageSize = params.get("pageSize")==null?10:Integer.parseInt(params.get("pageSize").toString());
		if(pageSize==-521) {
			//20190521 for:如果传此参数为-521 则表示不需要分页 直接走简单查询即可
			// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//List<Map<String,Object>> dataList =  this.onlCgformFieldMapper.queryListBySql(sb.toString());
			List<Map<String,Object>> dataList =  this.onlineMapper.selectByCondition(sb.toString(), sqlParam);
			// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//log.info("---Online表单查询sql 不分页 : >>  "+sb.toString());
			//log.info("---Online表单查询sqlParam 不分页 : >>  "+sqlParam.toString());
			if(dataList==null || dataList.size()==0) {
				result.put("total",0);
				result.put("fieldList",fieldList);
			}else {
				result.put("total",dataList.size());
				result.put("fieldList",fieldList);
				result.put("records",CgformUtil.toLowerCasePageList(dataList));
			}
		}else {
			Integer pageNo = params.get("pageNo")==null?1:Integer.parseInt(params.get("pageNo").toString());
			Page<Map<String,Object>> page = new Page<>(pageNo,pageSize);
			//log.info("---Online表单查询sql: >>  "+ sb.toString());
			//log.info("---Online表单查询sqlParam: >>  "+ sqlParam.toString());
			// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//IPage<Map<String,Object>> pageList = this.onlCgformFieldMapper.selectPageBySql(page, sb.toString());
			IPage<Map<String,Object>> pageList =  this.onlineMapper.selectPageByCondition(page, sb.toString(), sqlParam);
			// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus

			//4.处理结果 返回需要的数据
			result.put("total",pageList.getTotal());
			result.put("records",CgformUtil.toLowerCasePageList(pageList.getRecords()));
		}
		return result;
	}

	@Override
	public Map<String, Object> queryAutoTreeNoPage(String tbname, String headId,Map<String,Object> params,List<String> needList,String pidField) {
		Map<String, Object> result = new HashMap<>();

		//1.查询字段集合
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, headId);
		query.orderByAsc(OnlCgformField::getOrderNum);
		List<OnlCgformField> allFieldList = this.list(query);

		//2.获取显示列
		List<OnlCgformField> fieldList = this.queryAvailableFields(headId, tbname, true, allFieldList,needList);

		//2.获取查询sql
		StringBuffer sb = new StringBuffer();
		//基础SQL
		CgformUtil.getAutoListBaseSql(tbname, fieldList, sb);
		//查询条件（数据权限）
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200723 for：online权限改造
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<SysPermissionDataRuleModel> authList = onlAuthDataService.queryUserOnlineAuthData(userId, headId);
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200820 for：online权限改造 遗漏 用户信息临时存储
		if(authList!=null && authList.size()>0){
			JeecgDataAutorUtils.installUserInfo(sysBaseAPI.getCacheUser(sysUser.getUsername()));
		}

		// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
		ConditionHandler handler = new ConditionHandler("t.");
		handler.setNeedList(needList);
		handler.setSubTableStr("");
		List<OnlineFieldConfig> fieldConfigs = CgformUtil.getOnlineFieldList(allFieldList);
		String conditionSql = handler.getConditionSql(fieldConfigs, params, authList);
		Map<String,Object> sqlParam = handler.getSqlParams();
		if(conditionSql.trim().length()>0){
			sb.append(" t ").append(CgformUtil.SQL_WHERE).append(conditionSql);
		}
		// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus

		// 拼接排序
		String orderBySql = getOrderBySql(allFieldList, params);
		sb.append(orderBySql);

		//3.分页查询
		Integer pageSize = params.get("pageSize")==null?10:Integer.parseInt(params.get("pageSize").toString());
		if(pageSize==-521) {
			//20190521 for:如果传此参数为-521 则表示不需要分页 直接走简单查询即可
			// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//List<Map<String,Object>> dataList =  this.onlCgformFieldMapper.queryListBySql(sb.toString());
			List<Map<String,Object>> dataList =  this.onlineMapper.selectByCondition(sb.toString(), sqlParam);
			// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//update-begin-author:lvdandan date:20200703 for:online树添加查询条件
			//如果为有条件查询，则查询所有符合条件数据，并返回子节点的根节点
			if("true".equals(params.get("hasQuery"))){
				List<Map<String,Object>> mapList = new ArrayList<>();
				for(Map<String,Object> map : dataList){
					//update-begin-author:taoyan date:20211227 for: JTC-189 【online-tree】增加查询条件 有查询值报错 pidfield为小写，实际数据大写
					String pidVal = CgformUtil.getMapValue(map, pidField);
					//update-end-author:taoyan date:20211227 for: JTC-189 【online-tree】增加查询条件 有查询值报错 pidfield为小写，实际数据大写
					//递归查询子节点的根节点
					if(pidVal != null && !"0".equals(pidVal)){
						Map<String,Object> rootVal = this.getTreeRoot(pidVal,tbname,headId,needList,pidField);
						if(rootVal != null && rootVal.size()>0 && !mapList.contains(rootVal)){
							mapList.add(rootVal);
						}
					}else{
						if(!mapList.contains(map)){
							mapList.add(map);
						}
					}
				}
				dataList = mapList;
			}
			//update-end-author:lvdandan date:20200703 for:online树添加查询条件
			//log.info("---queryAutoTreeNoPage---Online查询sql 不分页 :>>"+sb.toString());
			//log.info("---queryAutoTreeNoPage---Online查询sql 不分页sqlParam :>>"+sqlParam.toString());
			if(dataList==null || dataList.size()==0) {
				result.put("total",0);
				result.put("fieldList",fieldList);
			}else {
				result.put("total",dataList.size());
				result.put("fieldList",fieldList);
				result.put("records",CgformUtil.toLowerCasePageList(dataList));
			}
		}else {
			Integer pageNo = params.get("pageNo")==null?1:Integer.parseInt(params.get("pageNo").toString());
			Page<Map<String,Object>> page = new Page<>(pageNo,pageSize);
			//log.info("---queryAutoTreeNoPage---Online表单查询sql:>> "+sb.toString());
			//log.info("---queryAutoTreeNoPage---Online表单查询sqlParam:>> "+sqlParam.toString());
			//如果没有查询条件则分页查询根节点，如果有查询条件则不再分页
			// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			IPage<Map<String,Object>> pageList =  this.onlineMapper.selectPageByCondition(page, sb.toString(), sqlParam);
			//IPage<Map<String,Object>> pageList = this.onlCgformFieldMapper.selectPageBySql(page, sb.toString());
			// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
			//4.处理结果 返回需要的数据
			result.put("total",pageList.getTotal());
			result.put("records",CgformUtil.toLowerCasePageList(pageList.getRecords()));
		}
		return result;
	}

	/**
	 * lvdandan 20200703
	 * online树添加查询条件,获取子节点的根节点
	 * @return
	 */
	private Map<String,Object> getTreeRoot(String pidVal,String tbname, String headId,List<String> needList,String pidField){
		Map<String,Object> params = new HashMap<>();
		params.put("id",pidVal);
		//1.查询字段集合
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, headId);
		query.orderByAsc(OnlCgformField::getOrderNum);
		List<OnlCgformField> allFieldList = this.list(query);

		//2.获取显示列
		List<OnlCgformField> fieldList = this.queryAvailableFields(headId, tbname, true, allFieldList,needList);
		//2.获取查询sql
		StringBuffer sb = new StringBuffer();
		//基础SQL
		CgformUtil.getAutoListBaseSql(tbname, fieldList, sb);
		//查询条件（数据权限）
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200727 for：online权限改造
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<SysPermissionDataRuleModel> authList = onlAuthDataService.queryUserOnlineAuthData(userId, headId);
		//UPDATE-BEGIN-AUTHOR:taoyan date:20200820 for：online权限改造 遗漏 用户信息临时存储
		if(authList!=null && authList.size()>0){
			JeecgDataAutorUtils.installUserInfo(sysBaseAPI.getCacheUser(sysUser.getUsername()));
		}
		// update-begin---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus
		ConditionHandler handler = new ConditionHandler("t.");
		handler.setNeedList(needList);
		handler.setSubTableStr("");
		List<OnlineFieldConfig> fieldConfigs = CgformUtil.getOnlineFieldList(allFieldList);
		String conditionSql = handler.getConditionSql(fieldConfigs, params, authList);
		Map<String,Object> sqlParam = handler.getSqlParams();
		sb.append(" t ").append(CgformUtil.SQL_WHERE).append(" id = '").append(pidVal).append("' ");
		if(conditionSql.trim().length()>0){
			sb.append(" and ").append(conditionSql);
		}

		//log.info("---getTreeRoot---Online表单查询sql:>> "+sb.toString());
		//log.info("---getTreeRoot---Online表单查询sqlParam:>> "+sqlParam.toString());
		List<Map<String,Object>> dataList =  this.onlineMapper.selectByCondition(sb.toString(), sqlParam);
		// update-end---author:taoyan   Date:20211015 for：LOWCOD-1765 【数据库兼容】查询兼容改造—数据库兼容性专项任务，底层看看用mybatisPlus

		if(dataList != null && dataList.size()>0){
			Map<String,Object> mapVal = dataList.get(0);
			if(mapVal != null && mapVal.get(pidField) != null && !"0".equals(mapVal.get(pidField))){
				return this.getTreeRoot(mapVal.get(pidField).toString(),tbname,headId,needList,pidField);
			}else{
				return mapVal;
			}
		}
		return null;
	}

	@Override
	public void saveFormData(String code,String tbname, JSONObject json,boolean isCrazy) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		List<OnlCgformField> fieldList = this.list(query);
		if(isCrazy) {
			baseMapper.executeInsertSQL(CgformUtil.getCrazyFormDataSaveSql(tbname, fieldList, json)) ;
		}else {
			baseMapper.executeInsertSQL(CgformUtil.getFormDataSaveSql(tbname, fieldList, json)) ;
		}
	}
	@Override
	public void saveTreeFormData(String code, String tbname, JSONObject json, String hasChildField, String pidField) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		List<OnlCgformField> fieldList = this.list(query);
		for (OnlCgformField item : fieldList) {
			//如果是否有子节点不显示 则新增一个节点时设置为0
			if(hasChildField.equals(item.getDbFieldName()) && item.getIsShowForm()!=1) {
				item.setIsShowForm(1);
				json.put(hasChildField, TREE_ROOT_PID);
				continue;
			}
			//如果父id为空 则设置为0 表示根节点
			if(pidField.equals(item.getDbFieldName()) && oConvertUtils.isEmpty(json.get(pidField))) {
				item.setIsShowForm(1);
				json.put(pidField, TREE_ROOT_PID);
			}
		}
		Map<String,Object> params = CgformUtil.getFormDataSaveSql(tbname, fieldList, json);
		baseMapper.executeInsertSQL(params);
		//保存当前节点时设置父级节点为有子节点
		if(!TREE_ROOT_PID.equals(json.getString(pidField))) {
			baseMapper.editFormData("update "+tbname +" set "+hasChildField+" = '1' where id = '"+json.getString(pidField)+"'");
		}
		
	}
	
	@Override
	public void saveFormData(List<OnlCgformField> fieldList, String tbname, JSONObject json) {
		Map<String,Object> params = CgformUtil.getFormDataSaveSql(tbname, fieldList, json);
		onlCgformFieldMapper.executeInsertSQL(params);
	}

	@Override
	public void editFormData(String code,String tbname, JSONObject json,boolean isCrazy) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		List<OnlCgformField> fieldList =  this.list(query);
		if(isCrazy) {
			onlCgformFieldMapper.executeUpdatetSQL(CgformUtil.getCrazyFormDataEditSql(tbname, fieldList, json)) ;
		}else {
			onlCgformFieldMapper.executeUpdatetSQL(CgformUtil.getFormDataEditSql(tbname, fieldList, json)) ;
		}
	}
	
	@Override
	public void editTreeFormData(String code, String tbname, JSONObject json,String hasChildField, String pidField) {
		//修改原父级节点加先父级节点
		String realTableName = CgformUtil.getRealTableName(tbname);
		String sql = "select * from "+realTableName+" where id = '"+json.getString("id") +"'";
		Map<String,Object> metaData = this.baseMapper.queryFormData(sql);
		//update-begin-author:taoyan date:20190927 for:oracle数据库大小写兼容问题
		Map<String,Object> metaDataLower = CgformUtil.transLowerCaseMapKey(metaData);
		String metaPid = metaDataLower.get(pidField).toString();
		//update-end-author:taoyan date:20190927 for:oracle数据库大小写兼容问题

		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		List<OnlCgformField> fieldList =  this.list(query);
		for (OnlCgformField item : fieldList) {
			//如果父id为空 则设置为0 表示根节点
			if(pidField.equals(item.getDbFieldName()) && oConvertUtils.isEmpty(json.get(pidField))) {
				item.setIsShowForm(1);
				json.put(pidField, TREE_ROOT_PID);
			}
		}
		Map<String,Object> params = CgformUtil.getFormDataEditSql(tbname, fieldList, json);
		//修改本级节点
		baseMapper.executeUpdatetSQL(params);
		
		if(!metaPid.equals(json.getString(pidField))) {
			//如果老数据的父级ID和新数据的父级ID不一致 那么求老数据的父级ID的子节点count
			if(!TREE_ROOT_PID.equals(metaPid)) {
				String countSql = "select count(*) from "+realTableName+" where "+pidField+" = '"+metaPid+"'";
				Integer count = baseMapper.queryCountBySql(countSql);
				if(count==null || count==0) {
					baseMapper.editFormData("update "+realTableName +" set "+hasChildField+" = '0' where id = '"+metaPid+"'");
				}
			}
			//编辑当前节点时设置父级节点为有子节点
			if(!TREE_ROOT_PID.equals(json.getString(pidField))) {
				baseMapper.editFormData("update "+realTableName +" set "+hasChildField+" = '1' where id = '"+json.getString(pidField)+"'");
			}
			
		}
		
	}

	@Override
	public Map<String, Object> queryFormData(String code, String tbname, String id) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		query.eq(OnlCgformField::getIsShowForm,1);
		List<OnlCgformField> fieldList =  this.list(query);
		String sql = CgformUtil.getSelectFormSql(tbname, fieldList, id);
		return onlCgformFieldMapper.queryFormData(sql);
	}


	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteAutoListMainAndSub(OnlCgformHead head, String ids) {
		if(head.getTableType()==2) {
			String headId = head.getId();
			String headName = head.getTableName();

			String tableName = "tableName"; //子表名key
			String linkField = "linkField";//子表外键字段key
			String linkValueStr = "linkValueStr";//子表外键字段值key(多值，逗号分隔)
			String mainField = "mainField";//子表外键关联主表的字段key
			//外键集合list, 找出 tablename  linkfiled mainField
			List<Map<String, String>> ls = new ArrayList<>();
			//子表数据删除逻辑
			if(StringUtil.isNotEmpty(head.getSubTableStr())){
				for (String tbname : head.getSubTableStr().split(",")) {
					//查询子表配置
					OnlCgformHead subTable = cgformHeadMapper.selectOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, tbname));
					if (subTable == null) {
						continue;
					}
					//查询子表配置的外键字段
					LambdaQueryWrapper query = new LambdaQueryWrapper<OnlCgformField>().eq(OnlCgformField::getCgformHeadId, subTable.getId()).eq(OnlCgformField::getMainTable, head.getTableName());
					List<OnlCgformField> subFieldList = this.list(query);
					if (subFieldList == null || subFieldList.size() == 0) {
						continue;
					}
					//TODO 目前外键只支持一个，不支持组合外键
					OnlCgformField subField = subFieldList.get(0);
					Map<String, String> map = new HashMap<>();
					//子表字段名字
					map.put(linkField, subField.getDbFieldName());
					//外键关联的主表字段
					map.put(mainField, subField.getMainField());
					//子表表名
					map.put(tableName, tbname);
					map.put(linkValueStr, "");
					ls.add(map);
				}

				LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
				query.eq(OnlCgformField::getCgformHeadId, headId);
				//查询主表的字段配置
				List<OnlCgformField> fieldList = this.list(query);
				//获取id数组
				String[] idArr = ids.split(CgformUtil.SQL_COMMA);

				for (String id: idArr) {
					// 删除主表数的时候 如果主表启用联合查询 传过来的id是 主表id@子表1id@子表2id 拼接成的串 所以截取第一个id才是主表id
					if(id.indexOf("@")>0){
						id = id.substring(0, id.indexOf("@"));
					}
					String sql = CgformUtil.getSelectFormSql(headName, fieldList, id);
					//获取主表数据
					Map<String, Object> map = onlCgformFieldMapper.queryFormData(sql);
					List<String> linkValueList = new ArrayList<>();
					for (Map<String, String> temp : ls) {
						Object linkValue = map.get(temp.get(mainField).toLowerCase());
						if(linkValue==null){
							linkValue = map.get(temp.get(mainField).toUpperCase());
						}
						if (linkValue == null) {
							continue;
						}
						String newLinkValue = temp.get(linkValueStr)+String.valueOf(linkValue)+CgformUtil.SQL_COMMA;
						temp.put(linkValueStr,newLinkValue);
					}
				}
				//删除子表数据
				for (Map<String, String> temp : ls) {
					deleteAutoList(temp.get(tableName),temp.get(linkField),temp.get(linkValueStr));
				}
			}
			//删除主表数据
			deleteAutoListById(head.getTableName(), ids);
		}
	}

	@Override
	public void deleteAutoListById(String tbname, String ids) {
		deleteAutoList(tbname, "id", ids);
	}
	
	@Override
	public void deleteAutoList(String tbname, String linkField, String linkValue) {
		if(linkValue!=null && !"".equals(linkValue)){
			String[] arr = linkValue.split(",");
			StringBuffer sb = new StringBuffer();
			for (String str : arr) {
				if(str==null||"".equals(str)) {
					continue;
				}
				//update-begin-author:taoyan date:20211227 for: JTC-223【online】达梦测试 一对多、一对一 tab（默认）批量删除不成功，其他好用
				if(str.indexOf("@")>0){
					str = str.substring(0, str.indexOf("@"));
				}
				//update-end-author:taoyan date:20211227 for: JTC-223【online】达梦测试 一对多、一对一 tab（默认）批量删除不成功，其他好用
				sb.append("'"+str+"',");
			}
			String temp = sb.toString();
			String sql = "DELETE FROM "+CgformUtil.getRealTableName(tbname) + " where "+linkField+" in("+temp.substring(0,temp.length()-1)+")";
			//log.debug("--删除sql-->"+sql);
			this.onlCgformFieldMapper.deleteAutoList(sql);
		}
	}

	@Override
	public List<Map<String, String>> getAutoListQueryInfo(String code) {
		int index = 0;
		OnlCgformHead head = this.cgformHeadMapper.selectOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getId, code));
		List<Map<String, String>> list = new ArrayList<>();
		//判断是否联合查询
		boolean isJoinQuery = CgformUtil.enableJoinQuery(head);
		index = handleTableQueryField(head, list, index, isJoinQuery);
		Integer tableType = head.getTableType();
		if(isJoinQuery && tableType!=null && 2 == tableType){
			// 联合查询且为主表 才需要找子表的查询条件
			String subTableStr = head.getSubTableStr();
			if(subTableStr!=null && !"".equals(subTableStr)){
				String[] arr = subTableStr.split(",");
				for(String subTableName: arr){
					OnlCgformHead subTable = cgformHeadMapper.selectOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, subTableName));
					if(subTable==null){
						continue;
					}
					index = handleTableQueryField(subTable, list, index, true);
				}

			}
		}
		return list;
	}

	@Override
	public List<OnlCgformField> queryFormFields(String code,boolean isform) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, code);
		if(isform) {
			query.eq(OnlCgformField::getIsShowForm,1);
		}
		return this.list(query);
	}

	@Override
	public List<OnlCgformField> queryFormFieldsByTableName(String tableName) {
		OnlCgformHead head = cgformHeadMapper.selectOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, tableName));
		if (head != null) {
			LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<>();
			query.eq(OnlCgformField::getCgformHeadId, head.getId());
			return this.list(query);
		}
		return null;
	}

	@Override
	public OnlCgformField queryFormFieldByTableNameAndField(String tableName, String fieldName) {
		OnlCgformHead head = cgformHeadMapper.selectOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, tableName));
		if (head != null) {
			LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<>();
			query.eq(OnlCgformField::getCgformHeadId, head.getId());
			query.eq(OnlCgformField::getDbFieldName,fieldName);
			if(this.list(query)!=null && this.list(query).size()>0){
				return this.list(query).get(0);
			}
		}
		return null;
	}

	@Override
	public Map<String, Object> queryFormData(List<OnlCgformField> fieldList, String tbname, String id) {
		String sql = CgformUtil.getSelectFormSql(tbname, fieldList, id);
		return onlCgformFieldMapper.queryFormData(sql);
	}

	@Override
	public List<Map<String, Object>> querySubFormData(List<OnlCgformField> fieldList, String tbname, String linkField,
			String value) {
		String sql = CgformUtil.getSelectSubFormSql(tbname, fieldList, linkField, value);
		return onlCgformFieldMapper.queryListData(sql);
	}

	@Override
	public IPage<Map<String, Object>> selectPageBySql(Page<Map<String, Object>> page, String sql) {
		return this.baseMapper.selectPageBySql(page, sql);
	}

	@Override
	public List<String> selectOnlineHideColumns(String tbname) {
		//update-begin-date:20200720--for: 【online】online视图按钮权限问题
		String onlineTbname = "online:"+tbname+":%";
		//update-end-date:20200720--for: 【online】online视图按钮权限问题
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<String> list = this.baseMapper.selectOnlineHideColumns(userId, onlineTbname);
		return handleRuleString(list);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<OnlCgformField> queryAvailableFields(String cgFormId,String tbname,String taskId,boolean isList) {
		
		//1.查询online配置的显示列
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, cgFormId);
		if(isList) {
			query.eq(OnlCgformField::getIsShowList,1);
		}else {
			query.eq(OnlCgformField::getIsShowForm,1);
		}
		query.orderByAsc(OnlCgformField::getOrderNum);
		List<OnlCgformField> fieldList = this.list(query);
		
		//2.查询角色授权的/菜单配置未授权的隐藏列
		String onlineTbname = "online:"+tbname+"%";
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<String> hideColumns = new ArrayList<String>();
		if(oConvertUtils.isEmpty(taskId)){
			//update-begin-author:taoyan date:20200723 for:online权限改造
			//查询被隐藏的列/按钮
			//List<String> onlineHideConfigColumns = this.baseMapper.selectOnlineHideColumns(userId, onlineTbname);
			List<String> onlineHideConfigColumns = this.onlAuthPageService.queryHideCode(userId,cgFormId,isList);
			//update-begin-author:taoyan date:20200723 for:online权限改造
			if(!(onlineHideConfigColumns==null || onlineHideConfigColumns.size()==0 || onlineHideConfigColumns.get(0)==null)) {
				hideColumns.addAll(onlineHideConfigColumns);
			}
		}else{
			//TODO 新权限 逻辑待测试
			//新增逻辑处理 流程字段权限控制
			if(StringUtil.isNotEmpty(taskId)){
				List<String> flowHideConfigColumns = this.baseMapper.selectFlowAuthColumns(tbname,taskId,"1");
				if(flowHideConfigColumns!=null && flowHideConfigColumns.size()>0 && flowHideConfigColumns.get(0)!=null){
					hideColumns.addAll(flowHideConfigColumns);
				}
			}
		}

		//3.过滤list
		if(hideColumns.size()==0){
			return fieldList;
		}
		
		/* jdk8循环效率
		  * 执行效率排序为 ：for > forEach > stream
		  * 开发效率排序为：for < forEach < stream
		  * 大数据量stream的效率会更好，这里没啥大数据 直接选择for
		 */
		List<OnlCgformField> result = new ArrayList<OnlCgformField>();
		//遍历字段集合 判断隐藏列是否包含每个字段 构造新的有效列集合
		for(int i=0;i<fieldList.size();i++) {
			OnlCgformField field = fieldList.get(i);
			if(handleRuleString(field.getDbFieldName(),hideColumns)) {
				result.add(field);
			}
		}
		return result;
	}
	
	@Override
	public List<String> queryDisabledFields(String tbname) {
		String onlineTbname = "online:"+tbname+"%";
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<String> disabledColumns = this.baseMapper.selectOnlineDisabledColumns(userId, onlineTbname);
		return handleRuleString(disabledColumns);
	}

	@Override
	public List<String> queryDisabledFields(String tbname, String taskId) {
		if(oConvertUtils.isEmpty(taskId)){
			return null;
		}
		List<String> disabledColumns = this.baseMapper.selectFlowAuthColumns(tbname,taskId,"2");
		return handleRuleString(disabledColumns);
	}

	/**
	 * 处理 online:tableName:filed 这样的字符串集合 返回filed集合
	 * @param columns
	 * @return
	 */
	private List<String> handleRuleString(List<String> columns){
		List<String> result = new ArrayList<String>();
		if(columns==null || columns.size()==0 || columns.get(0)==null) {
			return result;
		}
		for (String combineStr : columns) {
			if(oConvertUtils.isEmpty(combineStr)) {
				continue;
			}
			String fieldName = combineStr.substring(combineStr.lastIndexOf(":")+1);
			if(oConvertUtils.isEmpty(fieldName)) {
				continue;
			}
			result.add(fieldName);
		}
		return result;
	}

	/**
	 * 查询有效的列集合 (online配置为显示+角色授权显示)
	 * @param tbname 表名
	 * @param isList 是否是列表 true为列表字段 ，false为表单字段
	 * @param needList 树结构参数
	 * @return
	 */
	@Override
	public List<OnlCgformField> queryAvailableFields(String tbname,boolean isList,List<OnlCgformField> List,List<String> needList) {
		String onlineTbname = "online:"+tbname+"%";
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<String> hideColumns = this.baseMapper.selectOnlineHideColumns(userId, onlineTbname);
		return queryAvailableFields(hideColumns, isList, List, needList);
	}

	@Override
	public List<OnlCgformField> queryAvailableFields(String cgformId, String tbname, boolean isList, List<OnlCgformField> List, List<String> needList) {
		LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
		String userId = sysUser.getId();
		List<String> hideColumns = this.onlAuthPageService.queryListHideColumn(userId, cgformId);
		return queryAvailableFields(hideColumns, isList, List, needList);
	}

	private List<OnlCgformField> queryAvailableFields(List<String> hideColumns,boolean isList, List<OnlCgformField> List, List<String> needList){
		List<OnlCgformField> result = new ArrayList<OnlCgformField>();
		//查询是否存在未权限显示的字段
		boolean hasConfig = true;
		if(hideColumns==null || hideColumns.size()==0 || hideColumns.get(0)==null) {
			hasConfig = false;
		}

		for (OnlCgformField item : List) {
			String name = item.getDbFieldName();
			if(needList!=null && needList.contains(name)) {
				item.setIsQuery(1);
				result.add(item);
				continue;
			}

			//根据列表和表单，进行不同逻辑处理（根据字段配置的是否显示）
			if(isList) {
				//列表
				if(item.getIsShowList()!=1) {
					if(StringUtil.isNotEmpty(item.getMainTable()) && StringUtil.isNotEmpty(item.getMainField())){
						//隐藏的外键字段，需要加入list
						result.add(item);
						continue;
					}else{
						//字段配置隐藏，则跳过
						continue;
					}
				}
			}else {
				//表单
				if(item.getIsShowForm()!=1) {
					//字段配置隐藏，则跳过
					continue;
				}
			}

			//判断控件字段是否授权
			if(hasConfig) {
				if(handleRuleString(name,hideColumns)){
					result.add(item);
				}
			}else {
				result.add(item);
			}

		}
		return result;
	}

	/**
	 * 判断 当前filed 是不是在规则(隐藏)字段集合中 如果在则不操作
	 * @param filed
	 * @param ruleColumns
	 * @return
	 */
	private boolean handleRuleString(String filed,List<String> ruleColumns){
		boolean show = true;
		for(int j=0;j<ruleColumns.size();j++) {
			String combineStr = ruleColumns.get(j);
			if(oConvertUtils.isEmpty(combineStr)) {
				continue;
			}
			String ruleField = combineStr.substring(combineStr.lastIndexOf(":")+1);
			if(oConvertUtils.isEmpty(ruleField)) {
				continue;
			}
			if(ruleField.equals(filed)) {
				show = false;
			}
		}
		return show;
	}
	
	/**
	 * 判断字段名称是否真实有效
	 */
	public boolean hasField(String fieldName,List<OnlCgformField> List) {
		boolean flag = false;
		for (OnlCgformField field : List) {
			if(oConvertUtils.camelToUnderline(fieldName).equals(field.getDbFieldName())) {
				flag = true;
				break;
			}
		}
		return flag;
	}

	@Override
	public void executeInsertSQL(Map<String, Object> params) {
		baseMapper.executeInsertSQL(params);
	}

	@Override
	public void executeUpdatetSQL(Map<String, Object> params) {
		baseMapper.executeUpdatetSQL(params);
	}

	@Override
	public List<TreeModel> queryDataListByLinkDown(LinkDown linkDown) {
		return baseMapper.queryDataListByLinkDown(linkDown);
	}

	@Override
	public void updateTreeNodeNoChild(String tableName, String filed, String id) {
		Map<String, Object> params = CgformUtil.getTreeNodeNoChildSql(tableName,filed,id);
		baseMapper.executeUpdatetSQL(params);
	}

	@Override
	public String queryTreeChildIds(OnlCgformHead head,String ids) {
		String pidField = head.getTreeParentIdField();
		String tableName = head.getTableName();
		//获取id数组
		String[] idArr = ids.split(CgformUtil.SQL_COMMA);
		StringBuffer sb = new StringBuffer();
		for (String pidVal : idArr) {
			if(pidVal != null){
				if(!sb.toString().contains(pidVal)){
					if(sb.toString().length() > 0){
						sb.append(",");
					}
					sb.append(pidVal);
					this.getTreeChildIds(pidVal,pidField,tableName,sb);
				}
			}
		}
		return sb.toString();
	}

	@Override
	public String queryTreePids(OnlCgformHead head, String ids) {
		String pidField = head.getTreeParentIdField();
		String tableName = head.getTableName();
		StringBuffer sb = new StringBuffer();
		//获取id数组
		String[] idArr = ids.split(CgformUtil.SQL_COMMA);
		for (String id : idArr) {
			if(id != null){
				String realTableName = CgformUtil.getRealTableName(tableName);
				String sql = "select * from "+realTableName+" where id = '"+id +"'";
				Map<String,Object> metaData = this.baseMapper.queryFormData(sql);
				Map<String,Object> metaDataLower = CgformUtil.transLowerCaseMapKey(metaData);
				String metaPid = metaDataLower.get(pidField).toString();
				// update-begin--Author:sunjianlei  Date:20211227 for：【JTC-256】树表单功能测试无法删除数据
				// 给ids的每一项加上单引号
				String inIds = "'" + String.join("','", idArr) + "'";
				// update-end--Author:sunjianlei  Date:20211227 for：【JTC-256】树表单功能测试无法删除数据
				//查询此节点上一级是否还有其他子节点
				String childSql = "select * from " + CgformUtil.getRealTableName(tableName)+" where "+ pidField +"= '"+metaPid +"' and id not in("+inIds+")";
				List<Map<String,Object>> dataList =  this.onlCgformFieldMapper.queryListBySql(childSql);
				if((dataList == null || dataList.size()==0) && !Arrays.asList(idArr).contains(metaPid)
						&& !sb.toString().contains(metaPid)){
					//如果当前节点原本有子节点 现在木有了，更新状态
					sb.append(metaPid).append(CgformUtil.SQL_COMMA);
				}
			}
		}
		return sb.toString();
	}

	@Override
	public String queryForeignKey(String cgFormId,  String mainTable) {
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, cgFormId);
		query.eq(OnlCgformField::getMainTable, mainTable);
		List<OnlCgformField> fieldList = this.list(query);
		if(fieldList!=null && fieldList.size()>0){
			return fieldList.get(0).getMainField();
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> queryListBySql(String sql) {
		return this.onlCgformFieldMapper.queryListBySql(sql);
	}

	@Override
	public IPage<Map<String, Object>> selectPageBySql(String sql, int pageNo, int pageSize) {
		Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
		return this.onlCgformFieldMapper.selectPageBySql(page, sql);
	}

	/**
	 * 获取子节点
	 * @param pidVal
	 * @param pidField
	 * @param tableName
	 * @param sb
	 * @return
	 */
	private StringBuffer getTreeChildIds(String pidVal,String pidField,String tableName,StringBuffer sb){
		String sql = "select * from " + CgformUtil.getRealTableName(tableName)+" where "+ pidField +"= '"+pidVal +"'";
		List<Map<String,Object>> dataList =  this.onlCgformFieldMapper.queryListBySql(sql);
		if(dataList != null && dataList.size()>0){
			for(Map<String,Object> mapVal : dataList) {
				// update-begin---Author:lvdandan  Date:20201204  for：JT-37【online】树形列表删除bug
				//将mapVal转为小写 兼容oracle
				Map<String,Object> tempMap = CgformUtil.transLowerCaseMapKey(mapVal);
				// update-end---Author:lvdandan  Date:20201204  for：JT-37【online】树形列表删除bug
				if(!sb.toString().contains(tempMap.get("id").toString())){
					sb.append(",").append(tempMap.get("id"));
				}
				this.getTreeChildIds(tempMap.get("id").toString(),pidField,tableName, sb);
			}
		}
		return sb;
	}

	/**
	 * 获取排序的sql语句
	 * @param allFieldList
	 * @param params
	 * @return
	 */
	private String getOrderBySql(List<OnlCgformField> allFieldList, Map<String,Object> params){
		// 1.判断前端是否传过来排序 如果有那么使用该值排序
		Object columnParam = params.get("column");
		List<SqlOrder> ls = new ArrayList<SqlOrder>();
		if(columnParam!=null && !"id".equals(columnParam.toString())){
			String column = columnParam.toString();
			Object ruleString = params.get("order");
			String rule = SqlOrder.DESC;
			if(ruleString!=null){
				rule = ruleString.toString();
			}
			SqlOrder sqlOrder = new SqlOrder(column, rule);
			ls.add(sqlOrder);
		}else{
			// 2.前端没有传排序字段 用配置的排序字段
			for(OnlCgformField field: allFieldList){
				if("1".equals(field.getSortFlag())){
					String extJson = field.getFieldExtendJson();
					SqlOrder sqlOrder = new SqlOrder(field.getDbFieldName());
					if(extJson!=null && !"".equals(extJson)){
						JSONObject json = JSON.parseObject(extJson);
						String orderRule = json.getString(ExtendJsonKey.ORDER_RULE);
						if(orderRule!=null && !"".equals(orderRule)){
							sqlOrder.setRule(orderRule);
							// update-begin-author:taoyan date:20220119 for:JTC-489【online排序】如果用户不想修改默认的排序，但是设置了排序字段就会导致出问题
							ls.add(sqlOrder);
						}
					}
					// update-end-author:taoyan date:20220119 for:JTC-489【online排序】如果用户不想修改默认的排序，但是设置了排序字段就会导致出问题
				}
			}
			// 3.如果没有配置排序字段 那么使用默认的ID排序
			if(ls.size()==0){
				SqlOrder sqlOrder = SqlOrder.createDefaultOrder();
				ls.add(sqlOrder);
			}
		}

		// 最后 将sqlOrder转成sql语句
		List<String> sqlList = new ArrayList<>();
		for(SqlOrder sqlOrder: ls){
			if(hasField(sqlOrder.getColumn(), allFieldList)) {
				String temp = sqlOrder.getRealSql();
				sqlList.add(temp);
			}
		}
		return SqlOrder.ORDER_BY + String.join(",", sqlList);
	}

	/**
	 * 处理查询条件
	 * @param head
	 * @param list
	 * @param index
	 * @return
	 */
	private int handleTableQueryField(OnlCgformHead head, List<Map<String, String>> list, int index, boolean isJoinQuery){
		LambdaQueryWrapper<OnlCgformField> query = new LambdaQueryWrapper<OnlCgformField>();
		query.eq(OnlCgformField::getCgformHeadId, head.getId());
		query.eq(OnlCgformField::getIsQuery,1);
		query.orderByAsc(OnlCgformField::getOrderNum);
		List<OnlCgformField> fieldList =  this.list(query);
		for (OnlCgformField item : fieldList) {
			Map<String,String> map = new HashMap<>();
			map.put("label",item.getDbFieldTxt());
			if(isJoinQuery){
				// 查询条件 子表才需要加
				map.put("field", head.getTableName()+"@"+item.getDbFieldName());
			}else{
				map.put("field", item.getDbFieldName());
			}
			map.put("dbField",item.getDbFieldName());
			map.put("mode",item.getQueryMode());
			// 查询的时候也会用到该配置
			if(StringUtil.isNotEmpty(item.getFieldExtendJson())){
				map.put("fieldExtendJson",item.getFieldExtendJson());
			}
			String queryConfigFlag = item.getQueryConfigFlag();
			if("1".equals(queryConfigFlag)){
				//自定义查询配置
				String view = item.getQueryShowType();
				map.put("config","1");
				map.put("view", view);
				map.put("defValue",item.getQueryDefVal());
				if(CgformUtil.CAT_TREE.equals(view)){
					map.put("pcode",item.getQueryDictField());
				}else if(CgformUtil.SEL_TREE.equals(view)){
					//ID列,父ID列,显示列,是否有子节点列
					String[] arr = item.getQueryDictText().split(CgformUtil.SQL_COMMA);
					String dict = item.getQueryDictTable()+CgformUtil.SQL_COMMA+arr[2]+CgformUtil.SQL_COMMA+arr[0];
					map.put("dict",dict);
					map.put("pidField",arr[1]);
					map.put("hasChildField",arr[3]);
					map.put("pidValue",item.getQueryDictField());
				}else{
					map.put("dictTable",item.getQueryDictTable());
					map.put("dictCode",item.getQueryDictField());
					map.put("dictText",item.getQueryDictText());
				}
			}else{
				String view = item.getFieldShowType();
				map.put("view", view);
				map.put("mode",item.getQueryMode());
				//当  分类字典树控件 需要额外传这三个参数
				if(CgformUtil.CAT_TREE.equals(view)){
					map.put("pcode",item.getDictField());
				}
				//当  自定义树tree 需要额外传这三个参数
				else if(CgformUtil.SEL_TREE.equals(view)){
					//ID列,父ID列,显示列,是否有子节点列
					String[] arr = item.getDictText().split(CgformUtil.SQL_COMMA);
					String dict = item.getDictTable()+CgformUtil.SQL_COMMA+arr[2]+CgformUtil.SQL_COMMA+arr[0];
					map.put("dict",dict);
					map.put("pidField",arr[1]);
					map.put("hasChildField",arr[3]);
					map.put("pidValue",item.getDictField());
				} else{
					// CgformUtil.SEARCH CgformUtil.POPUP
					map.put("dictTable",item.getDictTable());
					map.put("dictCode",item.getDictField());
					map.put("dictText",item.getDictText());
				}

			}
			if((++index)>2) {
				map.put("hidden","1");
			}
			list.add(map);
		}
		return index;
	}


	@Override
	@CacheEvict(value = {CacheConstant.ONLINE_LIST, CacheConstant.ONLINE_FORM}, allEntries = true, beforeInvocation=true)
	public void clearCacheOnlineConfig() {
		//log.info("===this method body is empty, only for clear online cache===");
	}

}
